package pl.elka.simulator.gui.swt;

import pl.elka.simulator.core.Pair;
import pl.elka.simulator.core.Position;

public class PositionConverter {		
	
	public static Position convertToPosition(int x, int y){
		float xf = ((float)(x-CameraHints.xOffset))/(SWTMain.DRAW_BOARD_W/CameraHints.scale) - 0.5f;
		float yf = 0.5f - ((float)(y-CameraHints.yOffset))/(SWTMain.DRAW_BOARD_H/CameraHints.scale);
		
		return new Position(xf,yf);
	}
	public static Pair<Integer, Integer> convertFromPosition(Position position){
		float xf = position.getX();
		float yf = position.getY();
		
		int xi = (int)((xf+0.5)*SWTMain.DRAW_BOARD_W/(CameraHints.scale))+CameraHints.xOffset;
		int yi = (int)((0.5-yf)*SWTMain.DRAW_BOARD_H/(CameraHints.scale))+CameraHints.yOffset;
		
		return new Pair<Integer, Integer>(xi, yi);		
	}	
	public static int convertToScreenW(float w){
		return (int)(w*SWTMain.DRAW_BOARD_W/CameraHints.scale);
	}
	public static int convertToScreenH(float h){
		return (int)(h*SWTMain.DRAW_BOARD_H/CameraHints.scale);
	}
	
	public static class CameraHints {
		public static float scale=1;
		public static int xOffset=0;
		public static int yOffset=0;
	}
}
